package com.postgresql.service;


import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.MultiPolygon;
import com.vividsolutions.jts.io.WKTReader;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.postgresql.dao.GirdDao;
import com.postgresql.dto.Grid;

import java.util.List;

/**
 * @author: 顾志杰
 */
@Service
public class GridService {

    @Autowired
    private GirdDao girdDao;

    public void insert() throws Exception{
        Grid  grid = new Grid();
        WKTReader wktReader = new WKTReader();
        Geometry poing = wktReader.read("MULTIPOLYGON(((0 5,4 0,6 4,0 6,0 5)))");
        MultiPolygon polygon = (MultiPolygon) poing;
        polygon.setSRID(3857);
        grid.setGid(7);
        grid.setUserid(0);
        grid.setGridcode("003");
        grid.setGridmanage("姜文");
        grid.setOwnpart("不知道城管");
        grid.setGeom(polygon);
        girdDao.save(grid);
    }

    public List<Grid> findAll(){
        return girdDao.findAll();
    }
}
